package io.zcoder.innoway.activities;


import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.zcoder.innoway.R;
import io.zcoder.innoway.commons.PrefUtils;

public class WelcomeActivity extends BaseActivity {

    @BindView(R.id.splash)
    ImageView mImageSplash;

    @OnClick(R.id.join)
    void onJoin() {
        startActivity(new Intent(this, SelectTallActivity.class));
    }

    @OnClick(R.id.sign)
    void onSignIn() {
        startActivity(new Intent(this, LoginActivity.class));
    }

    CountDownTimer mTimer;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_welcome_activity);
        ButterKnife.bind(this);

        mTimer = new CountDownTimer(2000, 1000) {

            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {

                WelcomeActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (PrefUtils.getString(WelcomeActivity.this, PrefUtils.PREF_AUTHEN_TOKEN) != "") {
                            Intent intent = new Intent(WelcomeActivity.this, TopActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                        } else {
                            mImageSplash.setVisibility(View.GONE);
                        }
                    }
                });


            }
        };
        mTimer.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mTimer != null) {
            mTimer.onFinish();
        }
    }
}
